#include <header.h>
#include <iostream>

using std::cout;
using std::endl;

int main()
{
    const char *port = "1280";
    const char *ip = "127.0.0.1";

    int sockfd = socket(AF_INET,SOCK_STREAM,0);

    struct sockaddr_in sock;
    sock.sin_family = AF_INET;
    sock.sin_port = htons(atoi(port));
    sock.sin_addr.s_addr = inet_addr(ip);

    bind(sockfd,(const struct sockaddr *)&sock,sizeof(sock));

    listen(sockfd,10);

    struct sockaddr_in server;
    socklen_t len = sizeof(server);

    int netfd = accept(sockfd,(struct sockaddr *)&server,&len);
    while(1){
        /* if(netfd < 0) */
        /* { */
        /*     perror("accept error"); */
        /*     continue; */
        /* } */

        char buff[100];
        ssize_t ret = recv(netfd,buff,sizeof(buff),0);
        if(ret == 0){
            printf("对方断开连接");
            break;
        }
        printf("buff : %s\n",buff);

        memset(buff,sizeof(buff),0);
        ret = read(STDIN_FILENO,buff,sizeof(buff));
        send(netfd,buff,ret,0);


    }
    close(sockfd);
    close(netfd);

    return 0;
}

